package com.jilin.library.mapper;

import com.jilin.library.entity.PurchaseRecord;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface PurchaseRecordMapper {
    @Select("SELECT * FROM purchase_record")
    @Results({
        @Result(property = "book", column = "book_id", 
            one = @One(select = "com.jilin.library.mapper.BookMapper.findById"))
    })
    List<PurchaseRecord> findAll();
    
    @Select("SELECT * FROM purchase_record WHERE id = #{id}")
    @Results({
        @Result(property = "book", column = "book_id", 
            one = @One(select = "com.jilin.library.mapper.BookMapper.findById"))
    })
    PurchaseRecord findById(Integer id);
    
    @Insert("INSERT INTO purchase_record(book_id, quantity, price) " +
            "VALUES(#{bookId}, #{quantity}, #{price})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(PurchaseRecord record);
} 